
package pe.pucp.plugin.common;

import java.io.File;
import java.io.IOException;
import javax.swing.text.JTextComponent;
import org.netbeans.api.extexecution.ExternalProcessBuilder;

/**
 *
 * @author Diego
 */
public class LineaComando {
    TextComponentReaderThread tcRT;
    
    public LineaComando(String rutaPrograma, JTextComponent text, boolean showLastOnly) throws IOException {
        this(rutaPrograma, null, text, showLastOnly);
    }

    public LineaComando(String rutaPrograma, String directorioDeTrabajo, JTextComponent text, boolean showLastOnly) throws IOException {
        ExternalProcessBuilder epb = new ExternalProcessBuilder(rutaPrograma);
        if (directorioDeTrabajo != null && !directorioDeTrabajo.trim().equals("")) {
            File dT = new File(directorioDeTrabajo);
            if (dT.exists() && dT.isDirectory()) {
                epb.workingDirectory(dT);
            }
        }
        Process pr;
        pr = epb.call();
        tcRT = new TextComponentReaderThread(pr.getInputStream(),pr.getOutputStream(),pr.getErrorStream(),text, showLastOnly);
    }



    public void nuevoComando(String comando){
        tcRT.nuevoComando(comando);
    }
}
